#include <iostream>

// 类也有前置声明？
class BaseImplRegister;

class BaseImpl {
public:
    class Base {
    public:
        virtual void print() const = 0;
        virtual ~Base() = default;
    };

    BaseImpl() : BaseImpl(BaseImplRegister::getType()) {}
    explicit BaseImpl(Base* base) : base_(base) {}

private:
    Base* base_;
};

class Derived1 : public virtual BaseImpl::Base {
public:
    void print() const override { std::cout << "Print in derived1 " << std::endl; }
};

class Derived2 : public virtual BaseImpl::Base {
public:
    void print() const override { std::cout << "Print in derived2 " << std::endl; }
};

class BaseImplRegister {
public:
    static BaseImpl::Base* getType() {
        return new Derived1;
    }
};

int main() {
    BaseImpl::Base* pBase1 = new Derived1;
    BaseImpl::Base* pBase2 = new Derived2;
    pBase1->print();
    pBase2->print();

    return 0;
}